#include "Stu.h"

int main()
{
    key_t key = ftok(pathname, 0x6666);// 获取key值
    if(key < 0) return 1;

    int shm = shmget(key, 1024, IPC_CREAT | IPC_EXCL | 0666);// 创建共享内存
    if(shm < 0) return 2;

    Stu *s = shmat(shm, NULL, 0);// 关联共享内存

    // server读取学生信息
    char buffer[1024];
    while(1)
    {
        // 格式化到buffer
        snprintf(buffer, sizeof(buffer), "sid: %s\nname: %s\nage: %d\nspe: %s\ncla: %s\n",
             s->sid, s->name, s->age, s->spe, s->cla);

        printf("----------------\n");
        printf("server: \n%s", buffer);
        printf("----------------\n");
        sleep(2);
    }

    shmdt(s);// 共享内存去关联
    shmctl(shm, IPC_RMID, NULL); //释放共享内存

    return 0;
}